package cn.xuanxuanyuhua.crm.web.controller;

import cn.xuanxuanyuhua.crm.domain.Department;
import cn.xuanxuanyuhua.crm.query.QueryObject;
import cn.xuanxuanyuhua.crm.service.IDepartmentService;
import cn.xuanxuanyuhua.crm.util.JSONResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/department")
public class DepartmentController {

    @Autowired
    private IDepartmentService service;

    @RequestMapping("/list")
    public String list(Model m, QueryObject qo){
        m.addAttribute("pageInfo",service.query(qo));
        return "/department/list";
    }

    @RequestMapping("/saveOrUpdate")
    @ResponseBody
    public Object saveOrUpdate(Department entity){
        service.saveOrUpdate(entity);
        return new JSONResult();
    }

    @RequestMapping("/delete")
    @ResponseBody
    public Object delete(Long id){
        service.delete(id);
        return new JSONResult();
    }

}
